home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Risc World 3
/
Risc World 3.iso
/
SOFTWARE
/
ISSUE6
/
PD
/
PDF
/
pdf
/
c++
/
main
< prev
next >
Wrap
Text File
|
2003-02-24
|
7KB
|
250 lines
//--------------------------------------------------------------------------
//
// Copyright (c) 2002, Colin Granville
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or
// without modification, are permitted provided that the following
// conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// * The name Colin Granville may not be used to endorse or promote
// products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//
//--------------------------------------------------------------------------
#include "GuiWindow.h"
#include "GuiTargets.h"
#include "GuiTask.h"
#include "Document.h"
#include "DocView.h"
#include "Flex.h"
#include "fstream.h"
#include <stdlib.h>
#include <stdarg.h>
#include "gtypes.h"
#include "Node.h"
#include "error.h"
#include "globalparams.h"
#include "strstream.h"
#include "UserEvents.h"
#include "GuiIconbar.h"
#include "GuiFlexGlobal.h"
// first part is the xpdf version number
#ifndef __APCS_32
#define VERSION "2.01.1.11"
#else
#define VERSION "2.01.1.11 32bit"
#endif
class Application : public Node
{
public:
Application(int argc,char** argv);
virtual Node* removeChild(Node*);
virtual bool hasChildNodes() {return 1;}
DECLARE_RTTI_DERIVED(Application,Node);
private:
GuiIconbar iconbar;
virtual ~Application() {}
bool createDocument(const char* filename);
GUI_DECLARE_EVENT_TARGETS(Application);
GuiToolboxTarget userQuitTarget;
Claim userQuit(GuiToolboxEvent&,const GuiIdBlock&);
GuiToolboxTarget showHelpTarget;
Claim showHelp(GuiToolboxEvent&,const GuiIdBlock&);
GuiMessageTarget messageQuitTarget;
Claim messageQuit(GuiWimpMessage&);
GuiMessageTarget dataOpenTarget;
Claim dataOpen(GuiWimpMessage&);
GuiMessageTarget dataLoadTarget;
Claim dataLoad(GuiWimpMessage&);
};
//*************************************************************************
Application::Application(int argc,char** argv)
: iconbar("Iconbar"),
userQuitTarget(0,User_Quit,this,Application::userQuit),
showHelpTarget(0,User_ShowHelp,this,Application::showHelp),
messageQuitTarget(GuiWimp_MQuit,this,Application::messageQuit),
dataOpenTarget(GuiWimp_MDataOpen,this,Application::dataOpen),
dataLoadTarget(GuiWimp_MDataLoad,this,Application::dataLoad)
{
char* file_name=0;
int i;
for (i=1;i<argc;i++)
{
file_name=argv[i];
}
if (file_name==0) iconbar.show();
if (!createDocument(file_name) && !iconbar.isShowing()) exit(EXIT_SUCCESS);
}
//*************************************************************************
bool Application::createDocument(const char* filename)
{
DocViewChoices choices;
return makeDocView(makeDocument(*this,filename),choices);
}
//*************************************************************************
Node* Application::removeChild(Node* n)
{
Node::removeChild(n);
if (getFirstChild()==0 && !iconbar.isShowing())
{
delete this;
exit(EXIT_SUCCESS);
}
return n;
}
//*************************************************************************
Claim Application::userQuit(GuiToolboxEvent&,const GuiIdBlock&)
{
delete this;
exit(EXIT_SUCCESS);
return CLAIM;
}
//*************************************************************************
Claim Application::showHelp(GuiToolboxEvent&,const GuiIdBlock&)
{
_swix(OS_CLI,_IN(0),"filer_run <pdf$dir>.!help");
return CLAIM;
}
//*************************************************************************
Claim Application::messageQuit(GuiWimpMessage&)
{
delete this;
exit(EXIT_SUCCESS);
return CLAIM;
}
//*************************************************************************
Claim Application::dataOpen(GuiWimpMessage& mess)
{
bool claim=0;
switch (mess.data.dataOpen.fileType)
{
case 0xadf: mess.acknowledge();
createDocument(mess.data.dataOpen.pathName);
return CLAIM;
}
return DONT_CLAIM;
}
//*************************************************************************
Claim Application::dataLoad(GuiWimpMessage& mess)
{
if (mess.data.dataLoad.destination.windowHandle!=-2) return DONT_CLAIM;
if (createDocument(mess.data.dataLoad.leafName))
{
mess.reply(GuiWimp_MDataLoadAck);
}
return CLAIM;
}
//*************************************************************************
//*************************************************************************
//*************************************************************************
class ProgramInfo
{
public:
ProgramInfo();
~ProgramInfo();
private:
GuiWindow info;
GuiDisplayField version;
GUI_DECLARE_EVENT_TARGETS(ProgramInfo);
GuiToolboxTarget atbs_target;
Claim atbs(GuiToolboxEvent&,const GuiIdBlock&);
};
ProgramInfo::ProgramInfo()
: info("ProgInfo"),
version(info,9),
atbs_target(&info,0x82880,this,ProgramInfo::atbs)
{
}
//*****************************************************************
ProgramInfo::~ProgramInfo()
{
}
//*****************************************************************
Claim ProgramInfo::atbs(GuiToolboxEvent&,const GuiIdBlock&)
{
char buf[64];
ostrstream out(buf,sizeof(buf));
out << VERSION << " (";
if (__DATE__[4] != ' ') out <<__DATE__[4];
out << __DATE__[5] << ' ';
out.write(__DATE__,3);
out <<' ' << (__DATE__+7) << ')';
version.setValue(out.str());
return CLAIM;
}
//*************************************************************************
//*************************************************************************
//*************************************************************************
int main(int argc,char** argv)
{
globalParams = new GlobalParams("");
globalParams->setErrQuiet(1);
guiTaskInitialise("<PDF$Dir>");
new Application(argc,argv);
ProgramInfo info;
for (;;) GuiRegister::poll();
}